//
//  YRMainTableViewController.swift
//  YRSinaSwiftVersion
//
//  Created by 夜神月 on 16/4/8.
//  Copyright © 2016年 yr. All rights reserved.
//

import UIKit

class YRMainTableViewController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
        let mainTabBar = YRMainTabBar()
        
        setValue(mainTabBar, forKey: "tabBar")
        
        setupChildViewControllers()
    }
    
    private func setupChildViewControllers() {
        setupChildViewController(YRHomeTableViewController(), imageName: "tabbar_home", title: "首页")
        setupChildViewController(YRMessageTableViewController(), imageName: "tabbar_message_center", title: "消息")
        setupChildViewController(YRDiscoverTableViewController(), imageName: "tabbar_discover", title: "发现")
        setupChildViewController(YRProfileTableViewController(), imageName: "tabbar_profile", title: "我")
    }
    
    private func setupChildViewController(controller: UIViewController, imageName: String, title: String) {
        controller.tabBarItem.image = UIImage(named: imageName)
        controller.tabBarItem.selectedImage = UIImage(named: imageName + "_selected")?.imageWithRenderingMode(.AlwaysOriginal)
        controller.title = title
        controller.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName : UIColor.orangeColor()], forState: .Selected)
        
        addChildViewController(UINavigationController(rootViewController: controller))
    }
}
